package com.buka.menu.dao;

import com.buka.menu.entity.Menu;
import com.buka.menu.entity.RoleMenu;
import com.buka.utils.JDBCUtil;

import java.util.List;

public class MenuDao {

    /***
     * 根据用户id查询角色列表
     * @param userId
     * @return
     */
    public List<Menu> listByUserId(Long userId) {
        String sql = "select * from menu m INNER JOIN t_role_menu rm on rm.mid = m.id" +
                "INNER JOIN role r on r.id = rm.rid " +
                "INNER JOIN t_user_role ur on r.id = ur.rid" +
                "INNER JOIN user u on u.id = ur.uid  where u.id = ?";

        return JDBCUtil.executeQuery(sql, Menu.class, userId);
    }

    /****
     *  根据角色id查询角色菜单关联管理表，获取关联管理对象
     * @param ridStr
     * @return
     */
    public List<RoleMenu> listRoleMenuByRids(String ridStr) {
        String sql = "select * from t_role_menu where rid in ("+  ridStr+")";
        return JDBCUtil.executeQuery(sql, RoleMenu.class);
    }

    /***
     * 根据菜单id查询菜单列表
     * @param midStr
     * @return
     */
    public List<Menu> listByIds(String midStr) {
        String sql = "select * from menu where id in ("+midStr+")";
        return JDBCUtil.executeQuery(sql, Menu.class);
    }
}
